package com.kermel.andromeda.data.settings;

import android.test.AndroidTestCase;

import com.kermel.andromeda.data.DateDisplayType;
import com.kermel.andromeda.data.settings.ClockSettings;
import com.kermel.andromeda.data.settings.ClockSettingsPersister;
import com.kermel.andromeda.test.fixture.TestClockSettings;

public class ClockSettingsPersisterTest extends AndroidTestCase {
    protected static final Boolean MILITARY_TIME_TRUE_FIXTURE = true;
    protected static final Boolean DISPLAY_SECONDS_TRUE_FIXTURE = true;
    protected static final Boolean DISPLAY_DATE_TRUE_FIXTURE = true;
    
    private ClockSettingsPersister persister;
    private ClockSettings clockSettings;
    
    protected void setUp() throws Exception {
        super.setUp();
        
        persister = new ClockSettingsPersister(getContext());
        clockSettings = new TestClockSettings();
    }

    protected void tearDown() throws Exception {
        clockSettings = null;
        persister = null;
        
        super.tearDown();
    }
    
    public void testThatPersisterIsAbleToStoreMilitaryTimeValue() {
        ((TestClockSettings)clockSettings).setMilitaryTime(MILITARY_TIME_TRUE_FIXTURE);
        
        boolean resultOfStore = persister.store(clockSettings);
        assertTrue(resultOfStore);
        
        ClockSettings retrievedSettings = new TestClockSettings();
        persister.retrieve(retrievedSettings);
        
        assertTrue(retrievedSettings.isMilitaryTime());
    }
    
    public void testThatPersisterIsAbleToStoreDisplaySecondsValue() {
        ((TestClockSettings)clockSettings).setDisplaySeconds(DISPLAY_SECONDS_TRUE_FIXTURE);
        
        boolean resultOfStore = persister.store(clockSettings);
        assertTrue(resultOfStore);
        
        ClockSettings retrievedSettings = new TestClockSettings();
        persister.retrieve(retrievedSettings);
        
        assertTrue(retrievedSettings.isDisplaySeconds());
    }
    
    public void testThatPersisterIsAbleToStoreDisplayDateValue() {
        ((TestClockSettings)clockSettings).setDisplayDate(DISPLAY_DATE_TRUE_FIXTURE);
        
        boolean resultOfStore = persister.store(clockSettings);
        assertTrue(resultOfStore);
        
        ClockSettings retrievedSettings = new TestClockSettings();
        persister.retrieve(retrievedSettings);
        
        assertTrue(retrievedSettings.isDisplayDate());
    }
    
    public void testThatPersisterIsAbleToStoreDateDisplayTypeValue() {
        ((TestClockSettings)clockSettings).setDateDisplayType(DateDisplayType.SHORT);
        
        boolean resultOfStore = persister.store(clockSettings);
        assertTrue(resultOfStore);
        
        ClockSettings retrievedSettings = new TestClockSettings();
        persister.retrieve(retrievedSettings);
        
        assertTrue(retrievedSettings.getDateDisplayType().isShort());
    }
    
}
